import { Injectable } from '@angular/core'
import { HttpClientService } from 'src/app/common/httpClient/http'
import { CommonUtil } from 'src/app/common/utils/common.util'
import { CoolLocalStorage } from 'src/app/common/coolStorage/cool-local-storage'

@Injectable({
  providedIn: 'root'
})
export class FollowService {
  estate = {
    pager: { Start: 0, Limit: 10 },
    filter: {
      Lambda: '',
      Navigations: []
    },
    sorters: [{ Property: 'item=>item.Id', Direction: 'Descending' }]
  }
  layout = {
    pager: { Start: 0, Limit: 10 },
    filter: {
      Lambda: '',
      Navigations: []
    },
    sorters: [{ Property: 'item=>item.Id', Direction: 'Descending' }]
  }
  activity = {
    pager: { Start: 0, Limit: 10 },
    filter: {
      Lambda: '',
      Navigations: []
    },
    sorters: [{ Property: 'item=>item.Id', Direction: 'Descending' }]
  }

  constructor(private http: HttpClientService, private utils: CommonUtil, private storage: CoolLocalStorage) {}

  getEstateList(Start, callback, errorBack?) {
    let user = ''
    let zone = this.storage.getItem('zone') || ''
    let userinfo = this.storage.getObject('userinfo')
    if (userinfo) {
      user = userinfo['Id']
    }
    let lambda = `item=>item.User==${user}&&item.zone==${zone}`
    this.estate.pager.Start = Start
    this.estate.filter.Lambda = lambda
    this.http.post(this.estate, '/House1/Json/ProjectFollowService.svc/QueryProjectSummary', callback, errorBack)
  }

  getLayoutList(Start, callback, errorBack?) {
    let user = ''
    let zone = this.storage.getItem('zone') || ''
    let userinfo = this.storage.getObject('userinfo')
    if (userinfo) {
      user = userinfo['Id']
    }
    let lambda = `item=>item.User==${user}&&item.zone==${zone}`
    this.layout.pager.Start = Start
    this.layout.filter.Lambda = lambda
    this.http.post(this.layout, '/House1/Json/LayoutFollowService.svc/QueryLayoutSummary', callback, errorBack)
  }

  getActivityList(Start, callback, errorBack?) {
    let user = ''
    let zone = this.storage.getItem('zone') || ''
    let userinfo = this.storage.getObject('userinfo')
    if (userinfo) {
      user = userinfo['Id']
    }
    let lambda = `item=>item.User==${user}&&item.zone==${zone}`
    this.layout.pager.Start = Start
    this.layout.filter.Lambda = lambda
    this.http.post(this.layout, '/House1/Json/PromotionFollowService.svc/QueryPromotionSummary', callback, errorBack)
  }
}
